<?php

namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

use App\Http\Model\Goods;
use App\Http\Model\Type;

use Hash;

class SearchController extends Controller
{
   
    public function pub2(){
            $link = \DB::table('sad_link')->orderBy('order','asc')->get();
            return $link;
        }
    static public function getCatePid($pid=0)
    {

        $ctype = new Type();

        $data = $ctype->where('pid',$pid)->get();
        
        $arr = [];

        foreach ($data as $key => $value) {
            
            $value['sub'] = self::getCatePid($value['id']);

            $arr[] = $value;
        }
        return $arr;

    }


    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function postIndex(Request $request)
    {
        //获取主页提交过来的数据
        // $search = $request->except('_token');
        // $sea = $search['search'];

        // $search = $request -> input('search','');



        //实例化goods数据库
        $goods = new Goods();

        $newest = $goods->orderBy('ctime')->take(3)->get();

         $count = $request -> input('count',3);
        $search = $request -> input('search','');
        $request = $request -> all();

        $data = $goods->where('title','like','%'.$search.'%')->paginate($count);

        $laytype = self::getCatePid();

        $link = $this -> pub2();
        return view('home.search.index',compact('link','data','newest','request','laytype'));

    }
    
      public function getIndex(Request $request)
    {

      



        //实例化goods数据库
        $goods = new Goods();

        $newest = $goods->orderBy('ctime')->take(3)->get();

            $search = $request -> input('search','');
            $count = $request -> input('count',3);
            $request = $request -> all();

        $data = $goods->where('title','like','%'.$search.'%')->paginate($count);


        $laytype = self::getCatePid();

        $link = $this->pub2();
        return view('home.search.index',compact('link','data','newest','request','laytype'));

    }


}
